<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin_commoncall extends CI_Model {

    function __construct() {
        parent::__construct();
        log_message('debug', 'Init Model Initialized');
        
       
    }
	

    function check_admin_login() {
        $userdata = $this->session->userdata('sess_admin_user');
        if (!$userdata) {
            redirect('secure/member/login');
        }
    }

    function send_mail($email=NULL, $subject=NULL, $body=NULL) {
	
        $this->email->clear();
        //--Email Config
        $email_config['protocol'] = 'mail';
        $email_config['wordwrap'] = FALSE;
        $email_config['mailtype'] = 'html';
        $email_config['charset'] = 'utf-8';
        $email_config['crlf'] = "\r\n";
        $email_config['newline'] = "\r\n";
        $this->email->initialize($email_config);

        $this->email->to($email);
        $this->email->from($this->settings_model->get_setting('default_email'), $this->settings_model->get_setting('webtitle'));
        $this->email->subject($subject);
        $this->email->message($body);
        $this->email->send();
    }

    //--Currency Format --//
    function currency($amount="00"){
    	setlocale(LC_MONETARY, 'en_IN');
    	$amount = money_format('%!i', $amount);
    	return $amount;
    }
    //--round --//
    function roundFormat($str="0"){
    	$nombre_format_francais = number_format($str, 0, ' ', ' ');
    	return $nombre_format_francais;
    }
    function number(){
    	$bits = explode('.',$price);
    	echo number_format($price,strlen($bits[1]),'.',',');
    }
    function upload($imageData=NULL){
    
    	if ($imageData['imagearray']['error'] == 0) {
    
    		$ext = preg_replace("/.*\.([^.]+)$/", "\\1", $imageData['imagearray']['name']);
    		$imagename=$imageData['imagearray']['name'];
    		$imagename=explode( '.',$imagename);
    		$imagename=$imagename[0];
    		if($imageData['customefilename']){
    			$filename=$imageData['customefilename'].'.'.$ext;
    		}
    		else{
    			$filename = $imagename.'.'.$ext;
    		}
    		if($imageData['namewithtime']=='Yes'||$imageData['namewithtime']=='yes'){
    			$filename=$imagename.time().'.'.$ext;
    			if($imageData['separator'])
    				$filename=$imagename.$imageData['separator'].time().'.'.$ext;
    		}
    		if($imageData['prefix'])
    			$filename=$imageData['prefix'].$filename;
    		 
    		$config['file_name'] = $filename;
    		$config['upload_path'] = $imageData['imagepath'];
    		$config['allowed_types'] = $imageData['allowedtype'];
    		$config['overwrite'] = $imageData['overwrite'];
    		$config['remove_spaces'] = $imageData['removespace'];
    
    		 
    		$this->load->library('upload', $config);
    		if (!$this->upload->do_upload('userfile')) {
    			 
    			if($imageData['errmessage'])
    				$imagedata=array('message'=>$imageData['errmessage'],'data'=>"" ,'code'=>0);
    			else
    				$imagedata=array('message'=>$this->upload->display_errors(),'data'=>"",'code'=>0);
    			return $imagedata;
    		}
    		//if sucessfull
    		else{
    			if($imageData['createthumb']=='Yes'||$imageData['createthumb']=='yes')
    			{
    				$thumb['image_library'] = 'gd2';
    				$thumb['source_image'] = $imageData['imagepath'].$filename;
    				$thumb['new_image'] = $imageData['thumbpath'];
    				$thumb['create_thumb'] = false;
    				$thumb['maintain_ratio'] = false;
    				$thumb['width'] = $imageData['thumbwidth'];
    				$thumb['height'] = $imageData['thumbheight'];
    				 
    				$this->load->library('image_lib', $thumb);
    				$this->image_lib->resize();
    				if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
    			}
    			if($imageData['sucessmessage'])
    				$imagedata=array('message'=>$imageData['sucessmessage'],'data'=>$filename,'code'=>1);
    			else
    				$imagedata=array('message'=>"Image Uploded Sucesfully...",'data'=>$filename,'code'=>1);
    			return $imagedata;
    		}
    
    
    		 
    	}
    }    

}


?>
